<template>
  <div class="login_bg">
      i am demo
  </div>
</template>

<script>
export default {
  data() {
    return {
      userType: "admin",
      ruleForm: {
        user: "admin",
        password: "admin",
        autologin: false,
      },
      rules: {
        user: [{ required: true, message: "请输入用户名", trigger: "blur" }],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
      islogin: false,
    };
  },
  watch: {
    userType(val) {
      if (val == "admin") {
        this.ruleForm.user = "000410";
        this.ruleForm.password = "123456";
      } else if (val == "user") {
        this.ruleForm.user = "user";
        this.ruleForm.password = "user";
      }
    },
  },
  created: function () {
    this.$TOOL.data.remove("TOKEN");
    this.$TOOL.data.remove("USER_INFO");
    this.$TOOL.data.remove("MENU");
    this.$TOOL.data.remove("PERMISSIONS");
    this.$TOOL.data.remove("grid");
    console.log(
      "%c SCUI %c Gitee: https://gitee.com/lolicode/scui",
      "background:#666;color:#fff;border-radius:3px;",
      ""
    );
  },
  mounted() {
    var menu = this.$TOOL.data.get("menu");
	console.info(menu);
  },
  methods: {
    async login() {
      this.islogin = true;
      // this.$TOOL.crypto.MD5(this.ruleForm.password),
      var data = {
        username: this.ruleForm.user,
        password: this.ruleForm.password,
        tenant: 2,
      };
      //获取token
      console.info(data);
      //获取token
      var user = await this.$HTTP.post(
        "http://127.0.0.1:8989/sydx-ybt/sys/login",
        data
      );
      console.info(user);
      if (user.code == 200) {
        this.$TOOL.data.set("TOKEN", user.token);
        this.$TOOL.data.set("USER_INFO", user.userInfo);
      } else {
        this.islogin = false;
        this.$message.warning(user.message);
        return false;
      }
      //获取菜单
      // var menu = null
      // if(this.ruleForm.user == 'admin'){
      // 	menu = await this.$API.system.menu.myMenus.get()
      // }else{
      // 	menu = await this.$API.demo.menu.get()
      // }
      // if(menu.code == 200){
      // 	this.$TOOL.data.set("MENU", menu.data.menu)
      // 	this.$TOOL.data.set("PERMISSIONS", menu.data.permissions)
      // }else{
      // 	this.islogin = false
      // 	this.$message.warning(menu.message)
      // 	return false
      // }

      this.$router.replace({
        path: "/home",
      });
      this.$message.success("Login Success 登录成功");
      this.islogin = false;
    },
  },
};
</script>

<style scoped>
</style>
